<?php
/*******************************************************************************
*         SecurityImages v2.0 Copyright 2005 Walter Cedric
*		www.waltercedric.com
*
*    This file is part of SecurityImages component for Joomla.
*
*    com_securityimages is free software; you can redistribute it and/or modify
*    it under the terms of the GNU General Public License as published by
*    the Free Software Foundation; either version 2 of the License, or
*    (at your option) any later version.
*
*    com_securityimages is distributed in the hope that it will be useful,
*    but WITHOUT ANY WARRANTY; without even the implied warranty of
*    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
*    GNU General Public License for more details.
*
*    You should have received a copy of the GNU General Public License
*    along with com_securityimages; if not, write to the Free Software
*    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
*******************************************************************************/
defined( '_JEXEC' ) or die( 'Restricted access' );
/**
 * return number of post pensing into table #__security_images
 * 
 */
function getNumberOfPostPendingInDatabase() {
  $database = & JFactory::getDBO();
  
  $database->setQuery("SELECT count(*) FROM #__security_images");
  $tempQuery = $database->loadResult();
    
  return $tempQuery;
}

/**
 * helper function to display the content of table, useful for debugging purpose
 * 
 * 
 * 
 */
function displayTopDataPostPendingFromDatabase($limit) {
  $database = & JFactory::getDBO();
  $database->setQuery("SELECT ID, insertdate, referenceid, hiddentext, retry FROM #__security_images ORDER by insertdate LIMIT ".$limit );
  $rows = $database->loadObjectList();
  # Table header
  ?>
  <table cellpadding="4" cellspacing="0" border="0" width="100%" class="adminlist">
      <tr>
        <th class="title"><div align="center">ID</div></th>
        <th class="title"><div align="left">insertdate</div></th>
        <th class="title"><div align="center">referenceid</div></th>
        <th class="title"><div align="center">hiddentext</div></th>
        <th class="title"><div align="center">retry</div></th>
      </tr>
      <tr>
  <?php
    $k = 0;
    for ($i=0, $n=count( $rows ); $i < $n; $i++) {
      $row = &$rows[$i];
      echo "<tr class='row$k'>";
      echo "<td align='left'>$row->ID</td>";
      echo "<td align='center'>$row->insertdate</td>";
      echo "<td align='center'>$row->referenceid</td>";
      echo "<td align='center'>$row->hiddentext</td>";
      echo "<td align='center'>$row->retry</td>";
    }
  ?>
    </tr>
  </table>
<?php
}


/**
 * 
 * @authors Walter Cedric
 */
function deletePendingPost() {
  $database = & JFactory::getDBO();
  
  $database->setQuery("delete FROM #__security_images");
  $database->query();
  
}

/**
 * 
 * @authors Walter Cedric
 */
function displayBackgroungImages($numberOfAvailableImages) {
  include(JPATH_SITE.'/administrator/components/com_securityimages/config.securityimages.php');
     
  if ($numberOfAvailableImages == 0)
   return "<tr><td>&nbsp;</td><td>No images found in ".JURL_SITE."/components/com_securityimages/$securityImagesPlugins/$securityImagesPluginsVersion/images/bg*.png</td></tr>";
  
  $html = "";
  for ($index = 1; $index <= $numberOfAvailableImages; $index++) {
	 $html .= "<tr><td>&nbsp;</td>";
	 $html .= "<td><img src=\"".JURL_SITE."/components/com_securityimages/plugins/$securityImagesPlugins/$securityImagesPluginsVersion/images/bg-L-".$index.".png\"/>&nbsp;<strong>(bg-L-".$index.".png)</strong></td>";
	 $html .= "<td><img src=\"".JURL_SITE."/components/com_securityimages/plugins/$securityImagesPlugins/$securityImagesPluginsVersion/images/bg-S-".$index.".png\"/>&nbsp;<strong>(bg-S-".$index.".png)</strong></td>";
	 $html .= "</tr>";
  }
  return $html;
}


/**
 * 
 * @authors Walter Cedric
 */
function getCopyright() {
	global  $securityImagesPlugins,$securityImagesPluginsVersion ;
	include(JPATH_SITE.'/administrator/components/com_securityimages/config.securityimages.php');
		
		
	$copyright .= "/************************************************************\n";
	$copyright .= "*\n";
	$copyright .= "*		SecurityImages plugin ".$securityImagesPlugins." v".$securityImagesPluginsVersion." Copyright 2005 Walter Cedric\n";
	$copyright .= "*		www.waltercedric.com\n";
	$copyright .= "*\n";
	$copyright .= "*    This file is part of SecurityImages component for Joomla.\n";
	$copyright .= "*\n";
	$copyright .= "*    com_securityimages is free software; you can redistribute it and/or modify\n";
	$copyright .= "*    it under the terms of the GNU General Public License as published by\n";
	$copyright .= "*    the Free Software Foundation; either version 2 of the License, or\n";
	$copyright .= "*    (at your option) any later version.\n";
	$copyright .= "*\n";
	$copyright .= "*    com_securityimages is distributed in the hope that it will be useful,\n";
	$copyright .= "*    but WITHOUT ANY WARRANTY; without even the implied warranty of\n";
	$copyright .= "*    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n";
	$copyright .= "*    GNU General Public License for more details.\n";
	$copyright .= "*\n";
	$copyright .= "*    You should have received a copy of the GNU General Public License\n";
	$copyright .= "*    along with com_securityimages; if not, write to the Free Software\n";
	$copyright .= "*    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA\n";
	$copyright .= "*\n";
	$copyright .= "*\n";
	$copyright .= "\************************************************************/\n";
	
	return  $copyright;
}
 
 
 
?>
